package com.hmall.item.web;


import com.hmall.common.dto.PageDTO;
import com.hmall.item.pojo.Item;
import com.hmall.item.service.IItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("item")
public class ItemController {

    @Autowired
    private IItemService itemService;


    @GetMapping("/list")
    public PageDTO pageInt(Integer page, Integer size) {
        PageDTO list = itemService.listLimit(page, size);
        return list;
    }

    @GetMapping()
    public Item selectById(@PathVariable("id") Long id) {
        Item item = itemService.getById(id);
        return item;
    }

    @PostMapping
    public void add(@RequestBody Item item) {
        itemService.add(item);
    }


    @PutMapping("/status/{id}/{status}")
    public void updateStatus(@PathVariable("id") Long id, @PathVariable("status") Integer status) {
        itemService.updateStatus(id, status);
    }


    @PutMapping()
    public void updates(@RequestBody Item item) {
         itemService.updates(item);
    }


    @DeleteMapping("/{id}")
    public void delectById(@PathVariable("id") Long id){
        itemService.delectById(id);
    }
}
